import 'package:flutter/material.dart';
import 'package:shake_animation_widget/shake_animation_widget.dart';

class HomePage extends StatefulWidget {
  final String title;

  const HomePage({Key key, this.title}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  ///抖动动画控制器
  ShakeAnimationController _shakeAnimationController1 =
      new ShakeAnimationController();
  ShakeAnimationController _shakeAnimationController2 =
      new ShakeAnimationController();
  ShakeAnimationController _shakeAnimationController3 =
      new ShakeAnimationController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
          backgroundColor: Colors.blue,
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                '旋转抖动',
              ),
              ShakeAnimationWidget(
                ///抖动控制器
                shakeAnimationController: _shakeAnimationController1,

                ///微旋转的抖动
                shakeAnimationType: ShakeAnimationType.RoateShake,

                ///设置不开启抖动
                isForward: false,

                ///默认为 0 无限执行
                shakeCount: 0,

                ///抖动的幅度 取值范围为[0,1]
                shakeRange: 0.2,

                ///执行抖动动画的子Widget
                child: RaisedButton(
                  color: Colors.blue,
                  child: Text(
                    '测试',
                    style: TextStyle(color: Colors.white),
                  ),
                  onPressed: () {
                    ///判断抖动动画是否正在执行
                    if (_shakeAnimationController1.animationRunging) {
                      ///停止抖动动画
                      _shakeAnimationController1.stop();
                    } else {
                      ///开启抖动动画
                      ///参数shakeCount 用来配置抖动次数
                      ///通过 controller start 方法默认为 1
                      _shakeAnimationController1.start(shakeCount: 1);
                    }
                  },
                ),
              ),
              Text(
                '左右抖动',
              ),
              ShakeAnimationWidget(
                shakeAnimationController: _shakeAnimationController2,
                shakeAnimationType: ShakeAnimationType.LeftRightShake,
                isForward: false,
                shakeCount: 0,
                shakeRange: 0.2,
                child: RaisedButton(
                  color: Colors.blue,
                  child: Text(
                    '测试',
                    style: TextStyle(color: Colors.white),
                  ),
                  onPressed: () {
                    if (_shakeAnimationController2.animationRunging) {
                      _shakeAnimationController2.stop();
                    } else {
                      _shakeAnimationController2.start(shakeCount: 1);
                    }
                  },
                ),
              ),
              Text(
                '斜角抖动',
              ),
              ShakeAnimationWidget(
                shakeAnimationController: _shakeAnimationController3,
                shakeAnimationType: ShakeAnimationType.SkewShake,
                isForward: false,
                shakeCount: 0,
                shakeRange: 0.2,
                child: RaisedButton(
                  color: Colors.blue,
                  child: Text(
                    '测试',
                    style: TextStyle(color: Colors.white),
                  ),
                  onPressed: () {
                    if (_shakeAnimationController3.animationRunging) {
                      _shakeAnimationController3.stop();
                    } else {
                      _shakeAnimationController3.start(shakeCount: 1);
                    }
                  },
                ),
              ),
              Text(
                '实现文字的抖动效果',
              ),
              ShakeTextAnimationWidget(
                ///需要设置抖动效果的文本
                animationString: "打开新标签页发现好内容，掘金、GitHub、Dribbble、ProductHunt 等站点内容轻松获取。快来安装掘金浏览器插件获取高质量内容吧！",

                ///字符间距
                space: 1.0,

                ///行间距
                runSpace: 10,

                ///文字的样式
                textStyle: TextStyle(
                  ///文字的大小
                  fontSize: 25,
                ),

                ///抖动次数
                shakeCount: 0,
              ),
            ],
          ),
        ));
  }
}
